package package_20220905;

public class LowArray {
	private long[] arr = new long[8];
	private int nItem = 0;
	
	//获取元素
	public long getItem(int i){
		return arr[i];
	}
	
	//插入元素
	public void insertItem(long data){
		arr[nItem++] = data;
	}
	
	//修改元素
	public void setItem(int i, long data) {
		arr[i] = data;
	}

	//打印数组
	public void display(){
		for(int i =0; i < nItem; i++){
			System.out.println(arr[i]);
		}
	}
	
	//查找元素
	public int find(long data) {
		for(int i = 0; i < nItem; i++) {
			if(arr[i] == data) {
				return i;
			}
		}
		return -1;  //表示没找到该元素
	}
	
	//删除元素
	public void delect(long data) {
		int i = 0;	
		for(; i < nItem; i++){
			if(arr[i] == data){
				break;
			}
		}
		
		for(int x = i; x < nItem-1; x++){
			arr[x] = arr[x + 1];
		}
		nItem--;
	}
	
	//返回数组大小
	public int size() {
		return nItem;
	}
}
